//
//  LineModifier.swift
//  BasicTools
//
//  Created by ikang on 2025/8/27.
//

import SwiftUI

struct LineModifier: ViewModifier {
    var lineHeight: CGFloat = 1
    var backgroundColor: Color = .gray
    var padding: EdgeInsets = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
    var isShowLine: Bool = false
    
    init(lineHeight: CGFloat, backgroundColor: Color, padding: EdgeInsets, isShowLine: Bool) {
        self.lineHeight = lineHeight
        self.backgroundColor = backgroundColor
        self.padding = padding
        self.isShowLine = isShowLine
    }
    
    func body(content: Content) -> some View {
        VStack(spacing: 0) { 
            content
            
            if isShowLine {
                Rectangle()
                    .fill(backgroundColor)
                    .frame(height: lineHeight)
                    .padding(padding)
            }
        }
        .contentShape(Rectangle())
    }
}

extension BasicWrapper where Base: View {
    public func lineModifier(lineHeight: CGFloat = 1, 
                             backgroundColor: Color = .gray, 
                             padding: EdgeInsets = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0), 
                             isShowLine: Bool = false) -> some View {
        
        base.modifier(LineModifier(lineHeight: lineHeight, 
                                   backgroundColor: backgroundColor, 
                                   padding: padding, 
                                   isShowLine: isShowLine))
    }
}



